@shzlx/ui-default 4.58.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/api.ts +61 -0
- package/backendlib/builder.ts +182 -0
- package/backendlib/markdown-it-imsize.ts +235 -0
- package/backendlib/markdown-it-katex.ts +139 -0
- package/backendlib/markdown-it-media.ts +163 -0
- package/backendlib/markdown-it-xss.ts +200 -0
- package/backendlib/markdown.js +64 -0
- package/backendlib/misc.ts +54 -0
- package/backendlib/template.ts +279 -0
- package/breakpoints.json +5 -0
- package/components/DOMAttachedObject.ts +128 -0
- package/components/autocomplete/AssignSelectAutoComplete.tsx +22 -0
- package/components/autocomplete/CustomSelectAutoComplete.tsx +23 -0
- package/components/autocomplete/DomainSelectAutoComplete.tsx +18 -0
- package/components/autocomplete/FileSelectAutoComplete.tsx +26 -0
- package/components/autocomplete/LanguageSelectAutoComplete.tsx +24 -0
- package/components/autocomplete/ProblemSelectAutoComplete.tsx +18 -0
- package/components/autocomplete/UserSelectAutoComplete.tsx +23 -0
- package/components/autocomplete/components/AssignSelectAutoComplete.tsx +118 -0
- package/components/autocomplete/components/DomainSelectAutoComplete.tsx +53 -0
- package/components/autocomplete/components/FileSelectAutoComplete.tsx +50 -0
- package/components/autocomplete/components/LanguageSelectAutoComplete.tsx +48 -0
- package/components/autocomplete/components/ProblemSelectAutoComplete.tsx +54 -0
- package/components/autocomplete/components/UserSelectAutoComplete.tsx +54 -0
- package/components/autocomplete/domainselectautocomplete.page.styl +6 -0
- package/components/autocomplete/index.tsx +110 -0
- package/components/autocomplete/problemselectautocomplete.page.styl +6 -0
- package/components/autocomplete/userselectautocomplete.page.styl +6 -0
- package/components/browser-update.page.ts +27 -0
- package/components/calendar/calendar.page.styl +129 -0
- package/components/calendar/index.js +367 -0
- package/components/clipboard.page.ts +23 -0
- package/components/contest/contest.page.styl +119 -0
- package/components/contest/contest.page.ts +23 -0
- package/components/contest/contest_sidebar.page.styl +21 -0
- package/components/contest/problem-contest-bg.png +0 -0
- package/components/contest/problem-contest-bg@2x.png +0 -0
- package/components/customFont.page.tsx +90 -0
- package/components/datepicker/datepicker.page.tsx +94 -0
- package/components/dialog/DomDialog.ts +145 -0
- package/components/dialog/dialog.page.styl +40 -0
- package/components/dialog/index.tsx +285 -0
- package/components/discussion/CommentBox.js +103 -0
- package/components/discussion/collapsible.page.styl +40 -0
- package/components/discussion/collapsible.page.tsx +62 -0
- package/components/discussion/comments.page.styl +142 -0
- package/components/discussion/comments.page.tsx +192 -0
- package/components/discussion/discussion.page.styl +17 -0
- package/components/discussion/history.page.tsx +81 -0
- package/components/discussion/reaction.page.styl +30 -0
- package/components/discussion/reaction.page.tsx +103 -0
- package/components/drop/drop.page.styl +40 -0
- package/components/dropdown/Dropdown.js +50 -0
- package/components/dropdown/dropdown.page.styl +33 -0
- package/components/dropdown/dropdown.page.ts +8 -0
- package/components/editor/cmeditor.page.ts +23 -0
- package/components/editor/cmeditor.styl +10 -0
- package/components/editor/index.tsx +293 -0
- package/components/editor/mdeditor.ts +60 -0
- package/components/editor/textareaHandler.ts +29 -0
- package/components/footer/footer.page.styl +94 -0
- package/components/footer/footer.page.ts +26 -0
- package/components/form/button.page.default.styl +59 -0
- package/components/form/button.page.styl +36 -0
- package/components/form/checkbox.page.styl +89 -0
- package/components/form/form.page.styl +200 -0
- package/components/form/form.page.ts +20 -0
- package/components/form/multiSelectCheckbox.page.js +46 -0
- package/components/form/radiobox.page.styl +62 -0
- package/components/form/select.page.styl +29 -0
- package/components/form/textbox.page.styl +79 -0
- package/components/form/textbox.page.ts +21 -0
- package/components/form/var.inc.styl +14 -0
- package/components/header/header.page.styl +79 -0
- package/components/highlighter/code-example.js +111 -0
- package/components/highlighter/highlighter.page.styl +99 -0
- package/components/highlighter/highlighter.page.ts +72 -0
- package/components/highlighter/meta.js +15 -0
- package/components/highlighter/prismjs.js +122 -0
- package/components/hint.page.styl +9 -0
- package/components/hint.ts +19 -0
- package/components/hitokoto/index.page.js +21 -0
- package/components/hotkey/hotkey.page.js +83 -0
- package/components/katex/katex.page.js +26 -0
- package/components/katex/katex.page.styl +2 -0
- package/components/languageselect.tsx +94 -0
- package/components/loader/loader.page.styl +40 -0
- package/components/mantine.page.tsx +39 -0
- package/components/marker/Marker.js +192 -0
- package/components/marker/MarkerReactive.js +55 -0
- package/components/marker/marker.page.js +8 -0
- package/components/marker/marker.page.styl +57 -0
- package/components/media/media.page.js +46 -0
- package/components/menu/menu-heading.page.js +28 -0
- package/components/menu/menu.page.js +18 -0
- package/components/menu/menu.page.styl +68 -0
- package/components/message/index.page.ts +166 -0
- package/components/message/worker.ts +110 -0
- package/components/messagepad/DialogueListItem.page.styl +28 -0
- package/components/messagepad/DialogueListItemComponent.jsx +39 -0
- package/components/messagepad/Message.page.styl +64 -0
- package/components/messagepad/MessageComponent.jsx +33 -0
- package/components/messagepad/MessagePad.page.styl +99 -0
- package/components/messagepad/MessagePadDialogueContentContainer.jsx +104 -0
- package/components/messagepad/MessagePadDialogueListContainer.jsx +49 -0
- package/components/messagepad/MessagePadInputContainer.jsx +100 -0
- package/components/messagepad/index.jsx +49 -0
- package/components/messagepad/reducers/activeId.ts +36 -0
- package/components/messagepad/reducers/dialogues.js +53 -0
- package/components/messagepad/reducers/index.ts +14 -0
- package/components/messagepad/reducers/inputs.js +43 -0
- package/components/messagepad/reducers/isPosting.ts +49 -0
- package/components/monaco/index.ts +178 -0
- package/components/monaco/languages/markdown.ts +97 -0
- package/components/monaco/languages/typescript.ts +45 -0
- package/components/monaco/languages/yaml.ts +22 -0
- package/components/monaco/loader.ts +96 -0
- package/components/monaco/monaco.styl +30 -0
- package/components/monaco/nls.js +31 -0
- package/components/monaco/schema/problemconfig.ts +123 -0
- package/components/navigation/hamburgers.page.styl +87 -0
- package/components/navigation/nav-logo-small_dark.png +0 -0
- package/components/navigation/navigation.page.js +203 -0
- package/components/navigation/navigation.page.styl +211 -0
- package/components/notification/index.ts +105 -0
- package/components/notification/notification.page.js +14 -0
- package/components/notification/notification.page.styl +84 -0
- package/components/nprogress.page.styl +50 -0
- package/components/omnisearch/index.page.tsx +124 -0
- package/components/omnisearch/omnibar.page.styl +138 -0
- package/components/pager/pager.page.styl +57 -0
- package/components/preview/preview.page.ts +187 -0
- package/components/problem/create.page.js +12 -0
- package/components/problem/list.page.js +9 -0
- package/components/problem/rp.page.styl +4 -0
- package/components/problem/tag.page.styl +84 -0
- package/components/problemconfig/BasicForm.tsx +92 -0
- package/components/problemconfig/ProblemConfigEditor.tsx +170 -0
- package/components/problemconfig/ProblemConfigForm.tsx +140 -0
- package/components/problemconfig/ProblemConfigTree.tsx +163 -0
- package/components/problemconfig/ProblemType.tsx +165 -0
- package/components/problemconfig/index.tsx +91 -0
- package/components/problemconfig/reducer/config.ts +173 -0
- package/components/problemconfig/reducer/index.ts +11 -0
- package/components/problemconfig/reducer/testdata.ts +16 -0
- package/components/problemconfig/tree/AddTestcase.tsx +137 -0
- package/components/problemconfig/tree/SelectionManager.tsx +140 -0
- package/components/problemconfig/tree/SubtaskSettings.tsx +180 -0
- package/components/problemconfig/tree/Testcase.tsx +98 -0
- package/components/profile/backgrounds/1.jpg +0 -0
- package/components/profile/backgrounds/10.jpg +0 -0
- package/components/profile/backgrounds/11.jpg +0 -0
- package/components/profile/backgrounds/12.jpg +0 -0
- package/components/profile/backgrounds/13.jpg +0 -0
- package/components/profile/backgrounds/14.jpg +0 -0
- package/components/profile/backgrounds/15.jpg +0 -0
- package/components/profile/backgrounds/16.jpg +0 -0
- package/components/profile/backgrounds/17.jpg +0 -0
- package/components/profile/backgrounds/18.jpg +0 -0
- package/components/profile/backgrounds/19.jpg +0 -0
- package/components/profile/backgrounds/2.jpg +0 -0
- package/components/profile/backgrounds/20.jpg +0 -0
- package/components/profile/backgrounds/21.jpg +0 -0
- package/components/profile/backgrounds/3.jpg +0 -0
- package/components/profile/backgrounds/4.jpg +0 -0
- package/components/profile/backgrounds/5.jpg +0 -0
- package/components/profile/backgrounds/6.jpg +0 -0
- package/components/profile/backgrounds/7.jpg +0 -0
- package/components/profile/backgrounds/8.jpg +0 -0
- package/components/profile/backgrounds/9.jpg +0 -0
- package/components/profile/backgrounds/gen_thumbnails.sh +7 -0
- package/components/profile/backgrounds/thumbnail/1.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/10.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/11.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/12.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/13.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/14.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/15.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/16.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/17.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/18.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/19.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/2.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/20.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/21.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/3.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/4.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/5.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/6.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/7.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/8.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/9.jpg +0 -0
- package/components/profile/profile.page.styl +23 -0
- package/components/react/DomComponent.tsx +14 -0
- package/components/react/IconComponent.tsx +20 -0
- package/components/record/record.page.styl +26 -0
- package/components/rotator/index.js +75 -0
- package/components/rotator/rotator.page.styl +20 -0
- package/components/scratchpad/DataInput.page.styl +17 -0
- package/components/scratchpad/DataInputComponent.jsx +45 -0
- package/components/scratchpad/Editor.page.styl +13 -0
- package/components/scratchpad/Panel.page.styl +18 -0
- package/components/scratchpad/PanelButton.page.styl +15 -0
- package/components/scratchpad/PanelButtonComponent.jsx +19 -0
- package/components/scratchpad/PanelComponent.jsx +25 -0
- package/components/scratchpad/ScratchpadEditorContainer.tsx +137 -0
- package/components/scratchpad/ScratchpadPretestContainer.jsx +57 -0
- package/components/scratchpad/ScratchpadRecordsContainer.jsx +45 -0
- package/components/scratchpad/ScratchpadRecordsRowContainer.jsx +83 -0
- package/components/scratchpad/ScratchpadSettings.tsx +48 -0
- package/components/scratchpad/ScratchpadToolbarContainer.jsx +190 -0
- package/components/scratchpad/Tab.page.styl +24 -0
- package/components/scratchpad/Toolbar.page.styl +53 -0
- package/components/scratchpad/ToolbarComponent.jsx +85 -0
- package/components/scratchpad/index.tsx +132 -0
- package/components/scratchpad/reducers/editor.ts +24 -0
- package/components/scratchpad/reducers/index.ts +17 -0
- package/components/scratchpad/reducers/pretest.ts +34 -0
- package/components/scratchpad/reducers/records.ts +40 -0
- package/components/scratchpad/reducers/state.ts +10 -0
- package/components/scratchpad/reducers/ui.ts +152 -0
- package/components/scratchpad/scratchpad.page.styl +55 -0
- package/components/scratchpad/var.inc.styl +2 -0
- package/components/selectUser.tsx +16 -0
- package/components/signin/signInDialog.page.js +84 -0
- package/components/signin/signin_dialog.page.styl +57 -0
- package/components/smoothscroll/smoothscroll.page.js +44 -0
- package/components/socket/index.ts +68 -0
- package/components/star/star.page.styl +20 -0
- package/components/star/star.page.ts +58 -0
- package/components/sticky/sticky.page.js +66 -0
- package/components/tab/Tab.js +168 -0
- package/components/tab/tab.page.js +9 -0
- package/components/tab/tab.page.styl +105 -0
- package/components/tab/var.inc.styl +3 -0
- package/components/table/StyledTable.js +51 -0
- package/components/table/styledTable.page.js +8 -0
- package/components/table/table.page.styl +73 -0
- package/components/time/time.page.js +47 -0
- package/components/tooltip/Tooltip.js +49 -0
- package/components/tooltip/tooltip.page.js +29 -0
- package/components/tooltip/tooltip.page.styl +69 -0
- package/components/training/training.page.styl +25 -0
- package/components/upload.tsx +103 -0
- package/components/vote/vote.page.js +43 -0
- package/components/zipDownloader/index.ts +157 -0
- package/constant/domain.js +21 -0
- package/constant/message.js +5 -0
- package/constant/record.js +52 -0
- package/context.ts +11 -0
- package/entry.js +72 -0
- package/hydro.ts +112 -0
- package/index.ts +226 -0
- package/lazyload.ts +69 -0
- package/locales/en.yaml +71 -0
- package/locales/ko.yaml +823 -0
- package/locales/zh.yaml +1137 -0
- package/locales/zh_TW.yaml +1133 -0
- package/misc/Page.ts +49 -0
- package/misc/PageLoader.js +31 -0
- package/misc/float.styl +14 -0
- package/misc/grid.styl +1048 -0
- package/misc/immersive-background.jpg +0 -0
- package/misc/immersive-background@2x.jpg +0 -0
- package/misc/immersive.styl +23 -0
- package/misc/nothing.styl +13 -0
- package/misc/puzzled_twd2.svg +1 -0
- package/misc/section.styl +105 -0
- package/misc/slideout.styl +46 -0
- package/misc/structure.styl +158 -0
- package/misc/textalign.styl +11 -0
- package/misc/typography.styl +485 -0
- package/package.json +148 -0
- package/polyfill.ts +90 -0
- package/postcss.config.js +15 -0
- package/sentry.ts +26 -0
- package/service-worker.ts +265 -0
- package/setting.yaml +98 -0
- package/templates/about.html +14 -0
- package/templates/bsod.html +35 -0
- package/templates/components/comments_discussion.html +165 -0
- package/templates/components/comments_solution.html +171 -0
- package/templates/components/contest.html +12 -0
- package/templates/components/form.html +214 -0
- package/templates/components/home.html +20 -0
- package/templates/components/homework.html +8 -0
- package/templates/components/md_hint.html +39 -0
- package/templates/components/noscript_note.html +15 -0
- package/templates/components/nothing.html +6 -0
- package/templates/components/paginator.html +25 -0
- package/templates/components/problem.html +33 -0
- package/templates/components/record.html +21 -0
- package/templates/components/sidemenu.html +11 -0
- package/templates/components/user.html +49 -0
- package/templates/contest_balloon.html +48 -0
- package/templates/contest_clarification.html +103 -0
- package/templates/contest_detail.html +56 -0
- package/templates/contest_edit.html +259 -0
- package/templates/contest_main.html +146 -0
- package/templates/contest_manage.html +80 -0
- package/templates/contest_print.html +27 -0
- package/templates/contest_problemlist.html +231 -0
- package/templates/contest_scoreboard.html +46 -0
- package/templates/contest_scoreboard_download_html.html +71 -0
- package/templates/contest_user.html +47 -0
- package/templates/discussion_create.html +28 -0
- package/templates/discussion_detail.html +149 -0
- package/templates/discussion_edit.html +30 -0
- package/templates/discussion_main_or_node.html +47 -0
- package/templates/domain_base.html +26 -0
- package/templates/domain_create.html +55 -0
- package/templates/domain_dashboard.html +45 -0
- package/templates/domain_edit.html +6 -0
- package/templates/domain_group.html +51 -0
- package/templates/domain_join.html +47 -0
- package/templates/domain_join_applications.html +67 -0
- package/templates/domain_permission.html +66 -0
- package/templates/domain_role.html +71 -0
- package/templates/domain_user.html +86 -0
- package/templates/domain_user_raw.html +5 -0
- package/templates/error.html +25 -0
- package/templates/home_domain.html +64 -0
- package/templates/home_files.html +16 -0
- package/templates/home_messages.html +9 -0
- package/templates/home_security.html +224 -0
- package/templates/home_settings.html +21 -0
- package/templates/homework_detail.html +82 -0
- package/templates/homework_edit.html +138 -0
- package/templates/homework_files.html +24 -0
- package/templates/homework_main.html +76 -0
- package/templates/layout/basic.html +27 -0
- package/templates/layout/home_base.html +13 -0
- package/templates/layout/html5.html +74 -0
- package/templates/layout/immersive.html +22 -0
- package/templates/layout/mail.html +31 -0
- package/templates/layout/simple.html +4 -0
- package/templates/layout/wiki_base.html +16 -0
- package/templates/main.html +22 -0
- package/templates/manage_base.html +24 -0
- package/templates/manage_config.html +6 -0
- package/templates/manage_dashboard.html +27 -0
- package/templates/manage_script.html +56 -0
- package/templates/manage_setting.html +6 -0
- package/templates/manage_user_import.html +23 -0
- package/templates/manage_user_priv.html +76 -0
- package/templates/partials/category.html +19 -0
- package/templates/partials/contest.html +3 -0
- package/templates/partials/contest_balloon.html +37 -0
- package/templates/partials/contest_sidebar.html +150 -0
- package/templates/partials/contest_sidebar_management.html +56 -0
- package/templates/partials/contest_user.html +19 -0
- package/templates/partials/discussion_edit_form.html +45 -0
- package/templates/partials/discussion_list.html +50 -0
- package/templates/partials/discussion_nodes_widget.html +17 -0
- package/templates/partials/files.html +49 -0
- package/templates/partials/footer.html +108 -0
- package/templates/partials/hamburger.html +7 -0
- package/templates/partials/header_mobile.html +12 -0
- package/templates/partials/homepage/bulletin.html +7 -0
- package/templates/partials/homepage/contest.html +48 -0
- package/templates/partials/homepage/discussion.html +13 -0
- package/templates/partials/homepage/discussion_nodes.html +4 -0
- package/templates/partials/homepage/error.html +5 -0
- package/templates/partials/homepage/hitokoto.html +6 -0
- package/templates/partials/homepage/homework.html +45 -0
- package/templates/partials/homepage/problem_search.html +13 -0
- package/templates/partials/homepage/ranking.html +39 -0
- package/templates/partials/homepage/recent_problems.html +17 -0
- package/templates/partials/homepage/starred_problems.html +15 -0
- package/templates/partials/homepage/suggestion.html +34 -0
- package/templates/partials/homepage/training.html +50 -0
- package/templates/partials/homework.html +3 -0
- package/templates/partials/homework_default_penalty_rules.yaml +6 -0
- package/templates/partials/homework_sidebar.html +93 -0
- package/templates/partials/login_dialog.html +56 -0
- package/templates/partials/manage_user_priv.html +78 -0
- package/templates/partials/nav.html +138 -0
- package/templates/partials/problem-sidebar-information.html +25 -0
- package/templates/partials/problem.html +2 -0
- package/templates/partials/problem_category_dialog.html +43 -0
- package/templates/partials/problem_default.md +26 -0
- package/templates/partials/problem_description.html +33 -0
- package/templates/partials/problem_files.html +63 -0
- package/templates/partials/problem_list.html +68 -0
- package/templates/partials/problem_lucky.html +10 -0
- package/templates/partials/problem_sidebar.html +14 -0
- package/templates/partials/problem_sidebar_contest.html +43 -0
- package/templates/partials/problem_sidebar_homework.html +42 -0
- package/templates/partials/problem_sidebar_normal.html +152 -0
- package/templates/partials/problem_stat.html +3 -0
- package/templates/partials/scoreboard.html +79 -0
- package/templates/partials/setting.html +92 -0
- package/templates/partials/training_default.json +14 -0
- package/templates/partials/training_detail.html +153 -0
- package/templates/partials/user.html +2 -0
- package/templates/partials/user_detail/activity.html +18 -0
- package/templates/partials/user_detail/solution.html +29 -0
- package/templates/problem_config.html +39 -0
- package/templates/problem_detail.html +150 -0
- package/templates/problem_edit.html +111 -0
- package/templates/problem_files.html +91 -0
- package/templates/problem_hack.html +41 -0
- package/templates/problem_import.html +58 -0
- package/templates/problem_main.html +100 -0
- package/templates/problem_solution.html +55 -0
- package/templates/problem_statistics.html +96 -0
- package/templates/problem_submit.html +40 -0
- package/templates/ranking.html +81 -0
- package/templates/record_detail.html +134 -0
- package/templates/record_detail_status.html +93 -0
- package/templates/record_detail_summary.html +19 -0
- package/templates/record_main.html +142 -0
- package/templates/record_main_tr.html +35 -0
- package/templates/status.html +75 -0
- package/templates/training_detail.html +120 -0
- package/templates/training_edit.html +68 -0
- package/templates/training_files.html +64 -0
- package/templates/training_main.html +107 -0
- package/templates/user_changemail_mail.html +6 -0
- package/templates/user_changemail_mail_sent.html +9 -0
- package/templates/user_delete_pending.html +10 -0
- package/templates/user_detail.html +181 -0
- package/templates/user_login.html +46 -0
- package/templates/user_logout.html +13 -0
- package/templates/user_lostpass.html +27 -0
- package/templates/user_lostpass_mail.html +6 -0
- package/templates/user_lostpass_mail_sent.html +9 -0
- package/templates/user_lostpass_with_code.html +29 -0
- package/templates/user_register.html +22 -0
- package/templates/user_register_mail.html +6 -0
- package/templates/user_register_mail_sent.html +9 -0
- package/templates/user_register_with_code.html +35 -0
- package/templates/user_sudo.html +54 -0
- package/templates/user_sudo_redirect.html +18 -0
- package/templates/wiki_help.html +189 -0
- package/theme/bp6-compat.css +48 -0
- package/theme/dark.styl +397 -0
- package/theme/default.js +33 -0
- package/typed.d.ts +20 -0
- package/utils/base.ts +209 -0
- package/utils/base64.js +104 -0
- package/utils/db.ts +32 -0
- package/utils/index.ts +73 -0
- package/utils/loadReactRedux.ts +32 -0
- package/utils/mediaQuery.ts +13 -0
- package/utils/pjax.js +148 -0
- package/utils/slide.ts +57 -0
package/README.md
ADDED
package/api.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* eslint-disable import/first */
|
|
2
|
+
export * from './components/dialog';
|
|
3
|
+
export { default as loadMonaco } from './components/monaco/loader';
|
|
4
|
+
export { default as Notification } from './components/notification';
|
|
5
|
+
export { default as Rotator } from './components/rotator';
|
|
6
|
+
export { default as selectUser } from './components/selectUser';
|
|
7
|
+
export { default as Socket } from './components/socket/index';
|
|
8
|
+
export { default as uploadFiles } from './components/upload';
|
|
9
|
+
export * from './components/zipDownloader';
|
|
10
|
+
export { default as download } from './components/zipDownloader';
|
|
11
|
+
export { Context, ctx, Service } from './context';
|
|
12
|
+
export { initPageLoader } from './hydro';
|
|
13
|
+
export * from './lazyload';
|
|
14
|
+
export * from './misc/Page';
|
|
15
|
+
export * from './utils';
|
|
16
|
+
export * from '@hydrooj/utils/lib/common';
|
|
17
|
+
export { AnsiUp } from 'ansi_up';
|
|
18
|
+
export { default as $ } from 'jquery';
|
|
19
|
+
export { default as _ } from 'lodash';
|
|
20
|
+
export { default as React } from 'react';
|
|
21
|
+
export * as redux from 'react-redux';
|
|
22
|
+
export { default as jsxRuntime } from 'react/jsx-runtime';
|
|
23
|
+
import ReactDOMMain from 'react-dom';
|
|
24
|
+
import ReactDOMClient from 'react-dom/client';
|
|
25
|
+
import { load } from './lazyload';
|
|
26
|
+
|
|
27
|
+
Object.assign(ReactDOMMain, ReactDOMClient);
|
|
28
|
+
|
|
29
|
+
export const ReactDOM = ReactDOMMain as typeof ReactDOMMain & typeof ReactDOMClient;
|
|
30
|
+
export default load;
|
|
31
|
+
export interface EventMap { }
|
|
32
|
+
|
|
33
|
+
import AutoComplete from './components/autocomplete';
|
|
34
|
+
import AssignSelectAutoComplete from './components/autocomplete/AssignSelectAutoComplete';
|
|
35
|
+
import CustomSelectAutoComplete from './components/autocomplete/CustomSelectAutoComplete';
|
|
36
|
+
import DomainSelectAutoComplete from './components/autocomplete/DomainSelectAutoComplete';
|
|
37
|
+
import ProblemSelectAutoComplete from './components/autocomplete/ProblemSelectAutoComplete';
|
|
38
|
+
import UserSelectAutoComplete from './components/autocomplete/UserSelectAutoComplete';
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
AssignSelectAutoComplete, AutoComplete, CustomSelectAutoComplete, DomainSelectAutoComplete, ProblemSelectAutoComplete, UserSelectAutoComplete,
|
|
42
|
+
};
|
|
43
|
+
export function addPage(page: import('./misc/Page').Page | (() => Promise<void> | void)) {
|
|
44
|
+
window.Hydro.extraPages.push(page);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare global {
|
|
48
|
+
interface Window {
|
|
49
|
+
LANGS: Record<string, any>;
|
|
50
|
+
lazyloadMetadata: Record<string, string>;
|
|
51
|
+
lazyModuleResolver: Record<string, any>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let UserContext: Record<string, any>; // eslint-disable-line
|
|
55
|
+
let UiContext: Record<string, any>; // eslint-disable-line
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Below are old version api compat
|
|
59
|
+
import $ from 'jquery';
|
|
60
|
+
|
|
61
|
+
Object.assign(window, { $, jQuery: $ });
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { tmpdir } from 'os';
|
|
2
|
+
import {
|
|
3
|
+
basename, join, relative, resolve,
|
|
4
|
+
} from 'path';
|
|
5
|
+
import {
|
|
6
|
+
Context, fs, Handler, Logger, NotFoundError, param, SettingModel, sha1,
|
|
7
|
+
size, SystemModel, Types, UiContextBase,
|
|
8
|
+
} from 'hydrooj';
|
|
9
|
+
import esbuild from 'esbuild';
|
|
10
|
+
|
|
11
|
+
declare module 'hydrooj' {
|
|
12
|
+
interface UI {
|
|
13
|
+
esbuildPlugins?: esbuild.Plugin[];
|
|
14
|
+
}
|
|
15
|
+
interface SystemKeys {
|
|
16
|
+
'ui-default.nav_logo_dark': string;
|
|
17
|
+
}
|
|
18
|
+
interface UiContextBase {
|
|
19
|
+
constantVersion?: string;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const vfs: Record<string, string> = {};
|
|
24
|
+
const hashes: Record<string, string> = {};
|
|
25
|
+
const logger = new Logger('ui');
|
|
26
|
+
const tmp = tmpdir();
|
|
27
|
+
|
|
28
|
+
const federationPlugin: esbuild.Plugin = {
|
|
29
|
+
name: 'federation',
|
|
30
|
+
setup(b) {
|
|
31
|
+
const packages = {
|
|
32
|
+
'react/jsx-runtime': 'jsxRuntime',
|
|
33
|
+
react: 'React',
|
|
34
|
+
'react-dom/client': 'ReactDOM',
|
|
35
|
+
'react-dom': 'ReactDOM',
|
|
36
|
+
jquery: '$',
|
|
37
|
+
};
|
|
38
|
+
b.onResolve({ filter: /^@hydrooj\/ui-default/ }, () => ({
|
|
39
|
+
path: 'api',
|
|
40
|
+
namespace: 'ui-default',
|
|
41
|
+
}));
|
|
42
|
+
for (const key in packages) {
|
|
43
|
+
b.onResolve({ filter: new RegExp(`^${key}$`) }, () => ({
|
|
44
|
+
path: packages[key],
|
|
45
|
+
namespace: 'ui-default',
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
b.onLoad({ filter: /.*/, namespace: 'ui-default' }, (args) => {
|
|
49
|
+
if (args.path === 'api') {
|
|
50
|
+
return {
|
|
51
|
+
contents: 'module.exports = window.HydroExports;',
|
|
52
|
+
loader: 'tsx',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
contents: `module.exports = window.HydroExports['${args.path}'];`,
|
|
57
|
+
loader: 'tsx',
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const build = async (contents: string) => {
|
|
64
|
+
const res = await esbuild.build({
|
|
65
|
+
tsconfigRaw: '{"compilerOptions":{"experimentalDecorators":true}}',
|
|
66
|
+
format: 'iife' as 'iife',
|
|
67
|
+
bundle: true,
|
|
68
|
+
outdir: tmp,
|
|
69
|
+
sourcemap: SystemModel.get('ui-default.nosourcemap') ? false : 'external',
|
|
70
|
+
splitting: false,
|
|
71
|
+
write: false,
|
|
72
|
+
target: ['chrome65'],
|
|
73
|
+
plugins: [
|
|
74
|
+
...(global.Hydro.ui.esbuildPlugins || []),
|
|
75
|
+
federationPlugin,
|
|
76
|
+
],
|
|
77
|
+
minify: !process.env.DEV,
|
|
78
|
+
stdin: {
|
|
79
|
+
contents,
|
|
80
|
+
sourcefile: 'stdin.ts',
|
|
81
|
+
resolveDir: tmp,
|
|
82
|
+
loader: 'ts',
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
if (res.errors.length) console.error(res.errors);
|
|
86
|
+
if (res.warnings.length) console.warn(res.warnings);
|
|
87
|
+
return res;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const applyCss = (css: string) => `
|
|
91
|
+
const style = document.createElement('style');
|
|
92
|
+
style.textContent = ${JSON.stringify(css)};
|
|
93
|
+
document.head.appendChild(style);
|
|
94
|
+
`;
|
|
95
|
+
|
|
96
|
+
export async function buildUI() {
|
|
97
|
+
const start = Date.now();
|
|
98
|
+
let totalSize = 0;
|
|
99
|
+
const entryPoints: string[] = [];
|
|
100
|
+
const lazyModules: string[] = [];
|
|
101
|
+
const newFiles = ['entry.js'];
|
|
102
|
+
for (const addon of Object.values(global.addons) as string[]) {
|
|
103
|
+
let publicPath = resolve(addon, 'frontend');
|
|
104
|
+
if (!fs.existsSync(publicPath)) publicPath = resolve(addon, 'public');
|
|
105
|
+
if (!fs.existsSync(publicPath)) continue;
|
|
106
|
+
const targets = fs.readdirSync(publicPath);
|
|
107
|
+
for (const target of targets) {
|
|
108
|
+
if (/\.page\.[jt]sx?$/.test(target)) entryPoints.push(join(publicPath, target));
|
|
109
|
+
if (/\.lazy\.[jt]sx?$/.test(target)) lazyModules.push(join(publicPath, target));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function addFile(name: string, content: string) {
|
|
113
|
+
vfs[name] = content;
|
|
114
|
+
hashes[name] = sha1(content).substring(0, 8);
|
|
115
|
+
logger.info('+ %s-%s: %s', name, hashes[name].substring(0, 6), size(content.length));
|
|
116
|
+
newFiles.push(name);
|
|
117
|
+
totalSize += content.length;
|
|
118
|
+
}
|
|
119
|
+
for (const m of lazyModules) {
|
|
120
|
+
const name = basename(m).split('.')[0];
|
|
121
|
+
const { outputFiles } = await build(`window.lazyModuleResolver['${name}'](require('${relative(tmp, m).replace(/\\/g, '\\\\')}'))`);
|
|
122
|
+
const css = outputFiles.filter((i) => i.path.endsWith('.css')).map((i) => i.text).join('\n');
|
|
123
|
+
for (const file of outputFiles) {
|
|
124
|
+
if (file.path.endsWith('.css')) continue;
|
|
125
|
+
addFile(basename(m).replace(/\.[tj]sx?$/, '.js'), (css ? applyCss(css) : '') + file.text);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const lang in global.Hydro.locales) {
|
|
129
|
+
if (!/^[a-zA-Z_]+$/.test(lang)) continue;
|
|
130
|
+
if (!global.Hydro.locales[lang].__interface) continue;
|
|
131
|
+
const str = `window.LOCALES=${JSON.stringify(global.Hydro.locales[lang][Symbol.for('iterate')])};`;
|
|
132
|
+
addFile(`lang-${lang}.js`, str);
|
|
133
|
+
}
|
|
134
|
+
const entry = await build([
|
|
135
|
+
`window.lazyloadMetadata = ${JSON.stringify(hashes)};`,
|
|
136
|
+
`window.LANGS=${JSON.stringify(SettingModel.langs)};`,
|
|
137
|
+
...entryPoints.map((i) => `import '${relative(tmp, i).replace(/\\/g, '\\\\')}';`),
|
|
138
|
+
].join('\n'));
|
|
139
|
+
const pages = entry.outputFiles.filter((i) => i.path.endsWith('.js')).map((i) => i.text);
|
|
140
|
+
const css = entry.outputFiles.filter((i) => i.path.endsWith('.css')).map((i) => i.text);
|
|
141
|
+
addFile('entry.js', `window._hydroLoad=()=>{
|
|
142
|
+
${css.length ? applyCss(css.join('\n')) : ''}
|
|
143
|
+
${pages.join('\n')}
|
|
144
|
+
};`);
|
|
145
|
+
UiContextBase.constantVersion = hashes['entry.js'];
|
|
146
|
+
for (const key in vfs) {
|
|
147
|
+
if (newFiles.includes(key)) continue;
|
|
148
|
+
delete vfs[key];
|
|
149
|
+
delete hashes[key];
|
|
150
|
+
}
|
|
151
|
+
logger.success('UI addons built in %d ms (%s)', Date.now() - start, size(totalSize));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
class UiConstantsHandler extends Handler {
|
|
155
|
+
noCheckPermView = true;
|
|
156
|
+
|
|
157
|
+
@param('name', Types.Filename)
|
|
158
|
+
async all(domainId: string, name: string) {
|
|
159
|
+
this.response.type = 'application/javascript';
|
|
160
|
+
if (!vfs[name]) throw new NotFoundError(name);
|
|
161
|
+
this.response.addHeader('ETag', hashes[name]);
|
|
162
|
+
this.response.body = vfs[name];
|
|
163
|
+
this.response.addHeader('Cache-Control', 'public, max-age=86400');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export async function apply(ctx: Context) {
|
|
168
|
+
ctx.Route('constant', '/lazy/:version/:name', UiConstantsHandler);
|
|
169
|
+
ctx.Route('constant', '/resource/:version/:name', UiConstantsHandler);
|
|
170
|
+
ctx.on('app/started', buildUI);
|
|
171
|
+
const debouncedBuildUI = ctx.debounce(buildUI, 2000);
|
|
172
|
+
const triggerHotUpdate = (path?: string) => {
|
|
173
|
+
if (path && !path.includes('/ui-default/') && !path.includes('/public/') && !path.includes('/frontend/')) return;
|
|
174
|
+
debouncedBuildUI();
|
|
175
|
+
};
|
|
176
|
+
ctx.on('system/setting', () => triggerHotUpdate());
|
|
177
|
+
ctx.on('system/setting-loaded', () => triggerHotUpdate());
|
|
178
|
+
ctx.on('app/watch/change', triggerHotUpdate);
|
|
179
|
+
ctx.on('app/watch/unlink', triggerHotUpdate);
|
|
180
|
+
ctx.on('app/i18n/update', debouncedBuildUI);
|
|
181
|
+
debouncedBuildUI();
|
|
182
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// Process 
|
|
2
|
+
// ^^^^^^^^ this size specification
|
|
3
|
+
function parseNextNumber(str, pos, max) {
|
|
4
|
+
const start = pos;
|
|
5
|
+
const result = {
|
|
6
|
+
ok: false,
|
|
7
|
+
pos,
|
|
8
|
+
value: '',
|
|
9
|
+
};
|
|
10
|
+
let code = str.charCodeAt(pos);
|
|
11
|
+
while (pos < max && ((code >= 0x30 /* 0 */ && code <= 0x39 /* 9 */) || code === 0x25 /* % */)) {
|
|
12
|
+
code = str.charCodeAt(++pos);
|
|
13
|
+
}
|
|
14
|
+
result.ok = true;
|
|
15
|
+
result.pos = pos;
|
|
16
|
+
result.value = str.slice(start, pos);
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function parseImageSize(str, pos, max) {
|
|
21
|
+
const result = {
|
|
22
|
+
ok: false,
|
|
23
|
+
pos: 0,
|
|
24
|
+
width: '',
|
|
25
|
+
height: '',
|
|
26
|
+
};
|
|
27
|
+
if (pos >= max) return result;
|
|
28
|
+
let code = str.charCodeAt(pos);
|
|
29
|
+
if (code !== 0x3D /* = */) return result;
|
|
30
|
+
pos++;
|
|
31
|
+
code = str.charCodeAt(pos);
|
|
32
|
+
if (code !== 0x78 /* x */ && (code < 0x30 || code > 0x39) /* [0-9] */) {
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
// parse width
|
|
36
|
+
const resultW = parseNextNumber(str, pos, max);
|
|
37
|
+
pos = resultW.pos;
|
|
38
|
+
// next charactor must be 'x'
|
|
39
|
+
code = str.charCodeAt(pos);
|
|
40
|
+
if (code !== 0x78 /* x */) { return result; }
|
|
41
|
+
pos++;
|
|
42
|
+
// parse height
|
|
43
|
+
const resultH = parseNextNumber(str, pos, max);
|
|
44
|
+
pos = resultH.pos;
|
|
45
|
+
result.width = resultW.value;
|
|
46
|
+
result.height = resultH.value;
|
|
47
|
+
result.pos = pos;
|
|
48
|
+
result.ok = true;
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default function plugin(md) {
|
|
53
|
+
md.inline.ruler.before('emphasis', 'image', (state, silent) => {
|
|
54
|
+
let attrs;
|
|
55
|
+
let code;
|
|
56
|
+
let label;
|
|
57
|
+
let pos;
|
|
58
|
+
let ref;
|
|
59
|
+
let res;
|
|
60
|
+
let title;
|
|
61
|
+
let width = '';
|
|
62
|
+
let height = '';
|
|
63
|
+
let token;
|
|
64
|
+
let tokens;
|
|
65
|
+
let start;
|
|
66
|
+
let href = '';
|
|
67
|
+
const oldPos = state.pos;
|
|
68
|
+
const max = state.posMax;
|
|
69
|
+
|
|
70
|
+
if (state.src.charCodeAt(state.pos) !== 0x21/* ! */) return false;
|
|
71
|
+
if (state.src.charCodeAt(state.pos + 1) !== 0x5B/* [ */) return false;
|
|
72
|
+
|
|
73
|
+
const labelStart = state.pos + 2;
|
|
74
|
+
const labelEnd = md.helpers.parseLinkLabel(state, state.pos + 1, false);
|
|
75
|
+
|
|
76
|
+
// parser failed to find ']', so it's not a valid link
|
|
77
|
+
if (labelEnd < 0) return false;
|
|
78
|
+
|
|
79
|
+
pos = labelEnd + 1;
|
|
80
|
+
if (pos < max && state.src.charCodeAt(pos) === 0x28/* ( */) {
|
|
81
|
+
//
|
|
82
|
+
// Inline link
|
|
83
|
+
//
|
|
84
|
+
|
|
85
|
+
// [link]( <href> "title" )
|
|
86
|
+
// ^^ skipping these spaces
|
|
87
|
+
pos++;
|
|
88
|
+
for (; pos < max; pos++) {
|
|
89
|
+
code = state.src.charCodeAt(pos);
|
|
90
|
+
if (code !== 0x20 && code !== 0x0A) { break; }
|
|
91
|
+
}
|
|
92
|
+
if (pos >= max) return false;
|
|
93
|
+
|
|
94
|
+
// [link]( <href> "title" )
|
|
95
|
+
// ^^^^^^ parsing link destination
|
|
96
|
+
start = pos;
|
|
97
|
+
res = md.helpers.parseLinkDestination(state.src, pos, state.posMax);
|
|
98
|
+
if (res.ok) {
|
|
99
|
+
href = state.md.normalizeLink(res.str);
|
|
100
|
+
if (state.md.validateLink(href)) {
|
|
101
|
+
pos = res.pos;
|
|
102
|
+
} else {
|
|
103
|
+
href = '';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// [link]( <href> "title" )
|
|
108
|
+
// ^^ skipping these spaces
|
|
109
|
+
start = pos;
|
|
110
|
+
for (; pos < max; pos++) {
|
|
111
|
+
code = state.src.charCodeAt(pos);
|
|
112
|
+
if (code !== 0x20 && code !== 0x0A) { break; }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// [link]( <href> "title" )
|
|
116
|
+
// ^^^^^^^ parsing link title
|
|
117
|
+
res = md.helpers.parseLinkTitle(state.src, pos, state.posMax);
|
|
118
|
+
if (pos < max && start !== pos && res.ok) {
|
|
119
|
+
title = res.str;
|
|
120
|
+
pos = res.pos;
|
|
121
|
+
|
|
122
|
+
// [link]( <href> "title" )
|
|
123
|
+
// ^^ skipping these spaces
|
|
124
|
+
for (; pos < max; pos++) {
|
|
125
|
+
code = state.src.charCodeAt(pos);
|
|
126
|
+
if (code !== 0x20 && code !== 0x0A) { break; }
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
title = '';
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// [link]( <href> "title" =WxH )
|
|
133
|
+
// ^^^^ parsing image size
|
|
134
|
+
if (pos - 1 >= 0) {
|
|
135
|
+
code = state.src.charCodeAt(pos - 1);
|
|
136
|
+
|
|
137
|
+
// there must be at least one white spaces
|
|
138
|
+
// between previous field and the size
|
|
139
|
+
if (code === 0x20) {
|
|
140
|
+
res = parseImageSize(state.src, pos, state.posMax);
|
|
141
|
+
if (res.ok) {
|
|
142
|
+
width = res.width;
|
|
143
|
+
height = res.height;
|
|
144
|
+
pos = res.pos;
|
|
145
|
+
|
|
146
|
+
// [link]( <href> "title" =WxH )
|
|
147
|
+
// ^^ skipping these spaces
|
|
148
|
+
for (; pos < max; pos++) {
|
|
149
|
+
code = state.src.charCodeAt(pos);
|
|
150
|
+
if (code !== 0x20 && code !== 0x0A) { break; }
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (pos >= max || state.src.charCodeAt(pos) !== 0x29/* ) */) {
|
|
157
|
+
state.pos = oldPos;
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
pos++;
|
|
161
|
+
} else {
|
|
162
|
+
//
|
|
163
|
+
// Link reference
|
|
164
|
+
//
|
|
165
|
+
if (typeof state.env.references === 'undefined') return false;
|
|
166
|
+
|
|
167
|
+
// [foo] [bar]
|
|
168
|
+
// ^^ optional whitespace (can include newlines)
|
|
169
|
+
for (; pos < max; pos++) {
|
|
170
|
+
code = state.src.charCodeAt(pos);
|
|
171
|
+
if (code !== 0x20 && code !== 0x0A) { break; }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (pos < max && state.src.charCodeAt(pos) === 0x5B/* [ */) {
|
|
175
|
+
start = pos + 1;
|
|
176
|
+
pos = md.helpers.parseLinkLabel(state, pos);
|
|
177
|
+
if (pos >= 0) {
|
|
178
|
+
label = state.src.slice(start, pos++);
|
|
179
|
+
} else {
|
|
180
|
+
pos = labelEnd + 1;
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
pos = labelEnd + 1;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// covers label === '' and label === undefined
|
|
187
|
+
// (collapsed reference link and shortcut reference link respectively)
|
|
188
|
+
label ||= state.src.slice(labelStart, labelEnd);
|
|
189
|
+
|
|
190
|
+
ref = state.env.references[md.utils.normalizeReference(label)];
|
|
191
|
+
if (!ref) {
|
|
192
|
+
state.pos = oldPos;
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
href = ref.href;
|
|
196
|
+
title = ref.title;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
//
|
|
200
|
+
// We found the end of the link, and know for a fact it's a valid link;
|
|
201
|
+
// so all that's left to do is to call tokenizer.
|
|
202
|
+
//
|
|
203
|
+
if (!silent) {
|
|
204
|
+
state.pos = labelStart;
|
|
205
|
+
state.posMax = labelEnd;
|
|
206
|
+
|
|
207
|
+
const newState = new state.md.inline.State(
|
|
208
|
+
state.src.slice(labelStart, labelEnd),
|
|
209
|
+
state.md,
|
|
210
|
+
state.env,
|
|
211
|
+
tokens = [],
|
|
212
|
+
);
|
|
213
|
+
newState.md.inline.tokenize(newState);
|
|
214
|
+
token = state.push('image', 'img', 0);
|
|
215
|
+
token.attrs = attrs = [['src', href],
|
|
216
|
+
['alt', '']];
|
|
217
|
+
token.children = tokens;
|
|
218
|
+
if (title) {
|
|
219
|
+
attrs.push(['title', title]);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (width !== '') {
|
|
223
|
+
attrs.push(['width', width]);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (height !== '') {
|
|
227
|
+
attrs.push(['height', height]);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
state.pos = pos;
|
|
232
|
+
state.posMax = max;
|
|
233
|
+
return true;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// https://github.com/waylonflinn/markdown-it-katex/blob/master/index.js
|
|
2
|
+
import katex from 'katex';
|
|
3
|
+
|
|
4
|
+
const limit = (typeof process !== 'undefined' && process.versions && process.versions.node) ? 50 : 1000;
|
|
5
|
+
|
|
6
|
+
function isValidDelim(state, pos) {
|
|
7
|
+
const max = state.posMax;
|
|
8
|
+
const prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
|
|
9
|
+
const nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
|
|
10
|
+
let canOpen = true;
|
|
11
|
+
let canClose = true;
|
|
12
|
+
if (prevChar === 0x09
|
|
13
|
+
||/* \t */ (nextChar >= 0x30/* "0" */ && nextChar <= 0x39/* "9" */)) canClose = false;
|
|
14
|
+
if (nextChar === 0x09/* \t */) canOpen = false;
|
|
15
|
+
return {
|
|
16
|
+
canOpen,
|
|
17
|
+
canClose,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function inline(state, silent) {
|
|
22
|
+
let pos;
|
|
23
|
+
if (state.src[state.pos] !== '$') return false;
|
|
24
|
+
let res = isValidDelim(state, state.pos);
|
|
25
|
+
if (!res.canOpen) {
|
|
26
|
+
if (!silent) state.pending += '$';
|
|
27
|
+
state.pos += 1;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
const start = state.pos + 1;
|
|
31
|
+
let match = start;
|
|
32
|
+
// eslint-disable-next-line no-cond-assign
|
|
33
|
+
while ((match = state.src.indexOf('$', match)) !== -1) {
|
|
34
|
+
pos = match - 1;
|
|
35
|
+
while (state.src[pos] === '\\') pos -= 1;
|
|
36
|
+
if ((match - pos) % 2) break;
|
|
37
|
+
match += 1;
|
|
38
|
+
}
|
|
39
|
+
if (match === -1) {
|
|
40
|
+
if (!silent) state.pending += '$';
|
|
41
|
+
state.pos = start;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (match - start === 0) {
|
|
45
|
+
if (!silent) state.pending += '$$';
|
|
46
|
+
state.pos = start + 1;
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
res = isValidDelim(state, match);
|
|
50
|
+
if (!res.canClose) {
|
|
51
|
+
if (!silent) state.pending += '$';
|
|
52
|
+
state.pos = start;
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
if (!silent) {
|
|
56
|
+
const token = state.push('math_inline', 'math', 0);
|
|
57
|
+
token.markup = '$';
|
|
58
|
+
token.content = state.src.slice(start, match);
|
|
59
|
+
}
|
|
60
|
+
state.pos = match + 1;
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function escapeHtml(unsafe) {
|
|
65
|
+
return unsafe
|
|
66
|
+
.replace(/&/g, '&')
|
|
67
|
+
.replace(/</g, '<')
|
|
68
|
+
.replace(/>/g, '>')
|
|
69
|
+
.replace(/"/g, '"')
|
|
70
|
+
.replace(/'/g, ''');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function block(state, start, end, silent) {
|
|
74
|
+
let lastLine;
|
|
75
|
+
let lastPos;
|
|
76
|
+
let found = false;
|
|
77
|
+
let pos = state.bMarks[start] + state.tShift[start];
|
|
78
|
+
let max = state.eMarks[start];
|
|
79
|
+
if (pos + 2 > max) return false;
|
|
80
|
+
if (state.src.slice(pos, pos + 2) !== '$$') return false;
|
|
81
|
+
pos += 2;
|
|
82
|
+
let firstLine = state.src.slice(pos, max);
|
|
83
|
+
if (silent) return true;
|
|
84
|
+
if (firstLine.trim().slice(-2) === '$$') {
|
|
85
|
+
firstLine = firstLine.trim().slice(0, -2);
|
|
86
|
+
found = true;
|
|
87
|
+
}
|
|
88
|
+
let next = start;
|
|
89
|
+
while (!found) {
|
|
90
|
+
next++;
|
|
91
|
+
if (next >= end) break;
|
|
92
|
+
pos = state.bMarks[next] + state.tShift[next];
|
|
93
|
+
max = state.eMarks[next];
|
|
94
|
+
if (pos < max && state.tShift[next] < state.blkIndent) break;
|
|
95
|
+
if (state.src.slice(pos, max).trim().slice(-2) === '$$') {
|
|
96
|
+
lastPos = state.src.slice(0, max).lastIndexOf('$$');
|
|
97
|
+
lastLine = state.src.slice(pos, lastPos);
|
|
98
|
+
found = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
state.line = next + 1;
|
|
102
|
+
const token = state.push('math_block', 'math', 0);
|
|
103
|
+
token.block = true;
|
|
104
|
+
token.content = (firstLine && firstLine.trim() ? `${firstLine}\n` : '')
|
|
105
|
+
+ state.getLines(start + 1, next, state.tShift[start], true)
|
|
106
|
+
+ (lastLine && lastLine.trim() ? lastLine : '');
|
|
107
|
+
token.map = [start, state.line];
|
|
108
|
+
token.markup = '$$';
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export default function plugin(md) {
|
|
113
|
+
const options = { throwOnError: false, strict: 'ignore' as 'ignore', displayMode: false };
|
|
114
|
+
const render = (latex: string, displayMode = false) => {
|
|
115
|
+
options.displayMode = displayMode;
|
|
116
|
+
try {
|
|
117
|
+
latex = latex.replace(/\\def\{\\([a-zA-Z0-9]+)\}/g, '\\def\\$1');
|
|
118
|
+
return katex.renderToString(latex, options);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (options.throwOnError) console.error(error);
|
|
121
|
+
return `<p class='${displayMode ? 'katex-block ' : ''}katex-error' title='${escapeHtml(error.toString())}'>${escapeHtml(latex)}</p>`;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const inlineRenderer = function (tokens, idx) {
|
|
125
|
+
if (tokens[idx].content.length > limit) return `$${escapeHtml(tokens[idx].content.trim())}$`;
|
|
126
|
+
return render(tokens[idx].content);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const blockRenderer = function (tokens, idx) {
|
|
130
|
+
if (tokens[idx].content.length > limit) return `$$${escapeHtml(tokens[idx].content.trim())}$$`;
|
|
131
|
+
return `${render(tokens[idx].content, true)}\n`;
|
|
132
|
+
};
|
|
133
|
+
md.inline.ruler.after('escape', 'math_inline', inline);
|
|
134
|
+
md.block.ruler.after('blockquote', 'math_block', block, {
|
|
135
|
+
alt: ['paragraph', 'reference', 'blockquote', 'list'],
|
|
136
|
+
});
|
|
137
|
+
md.renderer.rules.math_inline = inlineRenderer;
|
|
138
|
+
md.renderer.rules.math_block = blockRenderer;
|
|
139
|
+
}
|